//
//  HNSH_GroupNoticeViewController.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/18.
//

#import "HNSH_GroupNoticeViewController.h"

@interface HNSH_GroupNoticeViewController ()
/** */
@property (nonatomic, strong)UITextView * textView;
/** */
@property (nonatomic, strong)UIButton * doneBtn;
/** */
@property (nonatomic, strong)UILabel * titleLabel;
/** */
@property (nonatomic, strong)UIImageView * imgView;
/** */
@property (nonatomic, strong)UIView * segView;
@end

@implementation HNSH_GroupNoticeViewController

//MARK: Cycle Methods
- (void)viewDidLoad{
    [super viewDidLoad];
    [self showNavTitle:@"群公告" showLeftItem:YES];
    
    self.view.backgroundColor = [UIColor appWhiteLabelColor];
    [self addAllViews];
    [self addAllLayout];
}

- (void)addAllLayout{
    [self.textView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.right.mas_equalTo(-16);
        make.top.mas_equalTo(kNavBarAndStatusBarHeight + 18);
        make.height.mas_equalTo(300);
    }];
    [self.doneBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(64);
        make.height.mas_equalTo(44);
        make.top.mas_equalTo(kStatusBarHeight);
        make.right.mas_equalTo(0);
    }];
    
//    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(16);
//        make.width.height.mas_equalTo(40);
//        make.top.mas_equalTo(kNavBarAndStatusBarHeight + 20);
//    }];
//
//    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(66);
//        make.height.mas_equalTo(40);
//        make.top.mas_equalTo(kNavBarAndStatusBarHeight + 20);
//    }];
//
//    [self.segView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.left.mas_equalTo(20);
//        make.right.mas_equalTo(-20);
//        make.height.mas_equalTo(1);
//        make.top.mas_equalTo(kNavBarAndStatusBarHeight + 62);
//    }];
    
}

//MARK: Myself Methods
- (void)addAllViews{
    [self.view addSubview:self.textView];
    [self.view addSubview:self.doneBtn];
    
//    [self.view addSubview:self.imgView];
//    [self.view addSubview:self.titleLabel];
//    [self.view addSubview:self.segView];
}

//MARK: 修改群公告
- (void)doneBtnAction{
    if (!self.textView.text || !self.textView.text.length) {
        [self.view makeToast:@"请输入群公告"];
        return;
    }
    NSString * notice = self.textView.text;
    [HNSH_ChatNetServer requestRongCloudGroupChangeBulletinWithGroupId:self.targetId bulletin:notice success:^(ST_BaseNetModel * _Nullable responseObject) {
        if (responseObject.code == 0) {
            [kSTWindow makeToast:@"修改成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }
    } Failure:^(NSError * _Nullable error) {
        
    }];
}

//MARK: Getter Methods
- (UITextView *)textView{
    if (!_textView) {
        _textView = [UITextView new];
        _textView.font = [UIFont systemFontOfSize:12];
        _textView.placeholder = @"请输入群公告信息";
        _textView.placeholderColor = [UIColor appGrayLabelColor];
        _textView.textColor = [UIColor appBlackLabelColor];
        _textView.backgroundColor = [UIColor clearColor];
        _textView.text = self.bulletin;
    }
    return _textView;
}

- (UIButton *)doneBtn{
    if (!_doneBtn) {
        _doneBtn = [UIButton new];
        [_doneBtn setTitle:@"完成" forState:UIControlStateNormal];
        [_doneBtn setTitleColor:[UIColor appGreenColor] forState:UIControlStateNormal];
        _doneBtn.titleLabel.font = [UIFont systemFontOfSize:16];
        [_doneBtn addTarget:self action:@selector(doneBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _doneBtn;
}

- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont boldSystemFontOfSize:14];
        _titleLabel.textColor = [UIColor appBlackLabelColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.text = self.name;
    }
    return _titleLabel;
}

- (UIImageView *)imgView{
    if (!_imgView) {
        _imgView = [UIImageView new];
        _imgView.layer.cornerRadius = 8;
        _imgView.layer.masksToBounds = YES;
        _imgView.image = [UIImage imageNamed:@"chat_icon_myqun"];
    }
    return _imgView;
}
- (UIView *)segView{
    if (!_segView) {
        _segView = [UIView new];
        _segView.backgroundColor = [UIColor colorWithHexString:@"#F2F3F6"];
    }
    return _segView;
}
@end
